package Interface_Comparable;

import java.util.Arrays;
import java.util.Objects;

public class Test {
    public static void bubbleSort1(Student[] s){
        for (int i = 0; i < s.length - 1; i++) {
            for (int j = 0; j < s.length - 1 - i; j++) {
                if(s[j].age > s[j + 1].age){
                    Student tmp = s[j];
                    s[j] = s[j + 1];
                    s[j + 1] = tmp;
                }
            }
        }
    }
    public static void bubbleSort2(Comparable[] comp){
        for (int i = 0; i < comp.length - 1; i++) {
            for (int j = 0; j < comp.length - 1 - i; j++) {
                if(comp[j].compareTo(comp[j + 1]) > 0){
                    Comparable tmp = comp[j];
                    comp[j] = comp[j + 1];
                    comp[j + 1] = tmp;
                }
            }
        }
    }
    public static void main(String[] args) throws CloneNotSupportedException {
//        Student[] s = new Student[3];
//        s[0] = new Student("zhangsan", 25);
//        s[1] = new Student("lisi", 18);
//        s[2] = new Student("wangwu", 23);

//        Arrays.sort(s);
//        System.out.println(Arrays.toString(s));
//        bubbleSort1(s);
//        System.out.println(Arrays.toString(s));

//        bubbleSort2(s);
//        System.out.println(Arrays.toString(s));

        Student s1 = new Student("zhangsan", 26);
        Student s2 = new Student("lisi", 15);
        NameComparator n = new NameComparator();
        System.out.println(n.compare(s1, s2));

        AgeComparator a = new AgeComparator();
        System.out.println(a.compare(s1, s2));

        //浅拷贝 和 深拷贝
        Person p1 = new Person(10);
        System.out.println(p1);
        System.out.println(p1.m.m);
        Person p2 = (Person) p1.clone();
        p1.m.m = 19.9;
        System.out.println(p1.m.m);
        System.out.println(p2);
        System.out.println(p2.m.m);
    }
}
